<?php 
	$itemsPerPage = 20;
	
	$superCategoryID = $categoryID = $subcategoryID  = null;
	
	$bestCategory = false;
	
	if(!isset($productType))
	{
		$productType = null;
		
		if(getRequestParameter("super_category"))
		{
			$superCategory = get_category(getRequestParameter("super_category"), $_SESSION["language"]["id"]);
			if($superCategory)
			{
				$superCategoryID = $bestCategory = $superCategory["id"];
			}
			
		}
		
		if(getRequestParameter("category"))
		{
			$category = get_category(getRequestParameter("category"), $_SESSION["language"]["id"]);
			if($category)
			{
				$categoryID = $bestCategory = $category["id"];
			}
		}
		
		if(getRequestParameter("sub_category"))
		{
			$subcategory = get_category(getRequestParameter("sub_category"), $_SESSION["language"]["id"]);
			if($subcategory)
			{
				$subcategoryID = $bestCategory = $subcategory["id"];
			}
		}
		
		
		//$categoryID = $page["id"];
		
		/*$parentCategoryID = null;
		if(isset($page["parent_id"]) && $page["parent_id"] == 0)
		{
			$parentCategoryID = $page["parent_id"];
		}*/
	}

	if(isset($page["filters"]))
	{
		$filters = $page["filters"];
	}
	else
	{
		$page["filters"] = $filters = array();
	}
	
	
	$products = filter_products($bestCategory, false, $page["filters"], $itemsPerPage);
	if(count($products) == 0 && isset($page["parent_id"]) && $page["parent_id"] == 0)
	{
		$products = filter_products(false, false, $page["filters"], $itemsPerPage, "id", "asc", false, $page["id"]);
	}
	$totalItems = 0;
	if(isset($products[0]["num_rows"]))
	{
		$totalItems = $products[0]["num_rows"];
	}
	
	$showContact = true;
	$details = 1;
?>

<?php include("global-includes/breadcrumbs.php"); ?>

<?php if(isset($selectedCategory["children"]) && count($selectedCategory["children"]) > 0): ?>
	<div class="col-md-12" id="categoryNav">
		<h1><?php echo translate("navigheaza_prin_categoriile")?> <span><?php echo ($selectedCategory["alt_title"] != "" ? $selectedCategory["alt_title"] : $selectedCategory["name"]);?></span></h1>
		<?php foreach($selectedCategory["children"] as $category): ?>
			<a href="<?php echo site_url() . $category["url"]; ?>" title="<?php echo $category["name"]; ?>"><?php echo ucfirst($category["name"]); ?></a>
		<?php endforeach; ?>
	</div>
<?php endif;?>


<!-- LIST CONTENT -->
<div class="col-md-9 cols-4">
	<?php if($products): ?>
		<?php include("global-includes/sort-bar.php"); ?>
	<?php endif; ?>
	<!-- PRODUCTS LIST -->
	<div class="productHolder cols-1" type="0" items="<?php echo $settings["number_of_products"];?>" orderby="default" sort_order="asc">
		<?php include("html-includes/common/product-detail-list.php"); ?>
	</div>
	<!-- END PRODUCTS LIST -->
	
	<?php if($products): ?>
		<?php include("global-includes/pagination.php"); ?>
	<?php endif; ?>
	
</div><!-- END LIST CONTENT -->
			
<!-- SIDEBAR -->
	<?php include("html-includes/list/items/sidebar.php"); ?>
<!-- END LIST CONTENT -->

<input type="hidden" id="company_id" value="0" />
<input type="hidden" id="parent_category_id" value="<?php echo $superCategoryID?>" />
<input type="hidden" id="category_id" value="<?php echo $categoryID?>" />
<input type="hidden" id="subcategory_id" value="<?php echo $subcategoryID; ?>" />

<input type="hidden" id="product_type" value="<?php echo $productType?>" />
<input type="hidden" id="filters" value="<?php echo json_encode($filters); ?>" /> 
<input type="hidden" id="page_no" value="1" /> 

